<template>
	<view>
		<u-navbar title="我的收藏" placeholder :autoBack="true" leftIconColor="#fff" bgColor="#00000000"
			:titleStyle="titleStyle">
		</u-navbar>
		<u-tabs :list="tabList" lineColor="#E6A5B4" :scrollable="false" :activeStyle="activeStyle"
			:inactiveStyle="inactiveStyle" @click="onSelectClick" />
		<view class="listV">
			<scroll-view v-if="collectionList.length>0" style="height: 80vh;" :scroll-y="true" @scroll="onScroll"
				:scroll-with-animation="true" :refresher-enabled="true" :refresher-triggered="triggered"
				@refresherrefresh="onDataList" refresher-default-style="white" @scrolltolower="scrolltolower">
				<view v-if="mType=='coach'" class="itemV" v-for="(item,key) in collectionList" :key="key"
					@tap="onItemClick(item)">
					<image class="imageIv" :src="item.image"></image>
					<view class="rightV">
						<view class="nameTv">{{item.title}}</view>
						<view class="timeTv">{{item.memo}}</view>
					</view>
				</view>

				<view v-if="mType!='coach'" class="itemVto" v-for="(item,key) in collectionList" :key="key"
					@tap="onItemClick(item)">
					<image class="imageIvto" :src="item.image" mode="aspectFill"></image>
					<view class="rightVto">
						<view class="nameTvto">{{item.title}}</view>
						<view class="timeTvto">{{item.memo}}</view>
					</view>
				</view>

			</scroll-view>
			<view v-if="collectionList.length==0"
				style="justify-content: center; align-items: center; display: flex; height: 50vh; color: #8D8D8D;">
				暂无收藏
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				activeStyle: {
					"color": "#E6A5B4D",
					"font-size": "34rpx"
				},
				inactiveStyle: {
					"color": "#8D8D8D",
					"font-size": "32rpx"
				},
				tabList: [{
					name: '教练' //0
				}, {
					name: '团课' //1
				}, {
					name: '训练营' //2
				}, {
					name: '私教课' //3
				}, {
					name: '线上课' //4
				}],
				mPage: 1,
				scrollTop: 0,
				triggered: false,
				collectionList: [],
				mType: 'coach', //	combo团课   camp 训练营  online 线上课  personal 私教课 coach 教练
			}
		},
		onLoad() {
			this.getCollectionList()
		},
		methods: {
			onDataList() {
				if (this.scrollTop == 0) {
					this.triggered = true;
					this.mPage = 1
					this.getCollectionList()
				}
			},
			scrolltolower() { //上拉加载
				this.mPage++
				this.getCollectionList()
			},
			onScroll(e) {
				this.scrollTop = e.detail.scrollTop
			},
			getCollectionList() {
				this.$api.getCollectionList({
					type: this.mType,
					page: this.mPage
				}).then((res) => {
					if (this.mPage == 1) {
						this.collectionList = res.list;
					} else {
						this.collectionList.push(...res.list)
					}
					this.triggered = false;
				}).catch((e) => {
					this.triggered = false;
				})
			},
			onSelectClick(e) {
				let index = e.name;
				if (index == "教练") {
					this.mPage = 1;
					this.mType = "coach";
					this.getCollectionList();
				} else if (index == "团课") {
					this.mPage = 1;
					this.mType = "combo";
					this.getCollectionList();
				} else if (index == "训练营") {
					this.mPage = 1;
					this.mType = "camp";
					this.getCollectionList();
				} else if (index == "私教课") {
					this.mPage = 1;
					this.mType = "personal";
					this.getCollectionList();
				} else if (index == "线上课") {
					this.mPage = 1;
					this.mType = "online";
					this.getCollectionList();
				}
			},
			onItemClick(item) {
				//	combo团课   camp 训练营  online 线上课  personal 私教课 coach 教练
				if (this.mType == "personal") {
					this.$u.route({
						url: '/pages/schedule/TeachDetails',
						params: {
							id: item.id,
						}
					})
				} else if (this.mType == "camp") {
					this.$u.route({
						url: '/pages/schedule/BootcampDetails',
						params: {
							id: item.id,
						}
					})
				} else if (this.mType == "combo") {
					this.$u.route({
						url: '/pages/schedule/GroupDetails',
						params: {
							id: item.id,
						}
					})
				} else if (this.mType == "online") {
					this.$u.route({
						url: '/pages/schedule/OnlineDetails',
						params: {
							id: item.id,
						}
					})
				} else if (this.mType == "coach") {
					this.$u.route({
						url: '/pages/schedule/TeachAdd',
						params: {
							id: item.id,
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.listV {
		background-color: #E6A5B4;
		height: 83vh;

		.itemV {
			width: 100%;
			height: 150rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #383838;

			.imageIv {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin-left: 30rpx;
			}

			.rightV {
				margin-left: 16rpx;
				margin-right: 30rpx;

				.nameTv {
					font-size: 32rpx;
					color: #FFFFFF;
				}

				.timeTv {
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 10rpx;
				}
			}
		}

		.itemVto {
			width: 100%;
			height: 180rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #383838;

			.imageIvto {
				width: 160rpx;
				height: 120rpx;
				margin-left: 30rpx;
				border-radius: 10rpx;
			}

			.rightVto {
				margin-left: 16rpx;
				margin-right: 30rpx;

				.nameTvto {
					font-size: 32rpx;
					color: #FFFFFF;
				}

				.timeTvto {
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 30rpx;
					// background: #4A4A4A;
					// border-radius: 10rpx 0rpx 10rpx 0rpx;
					// margin-right: 10rpx;
					// padding-left: 18rpx;
					// padding-right: 18rpx;
					padding-top: 2rpx;
					padding-bottom: 2rpx;
				}
			}
		}
	}
</style>
